<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const _getUniqueNums = (start, end, n) => {
        // 补全代码
        var min = Math.ceil(start)
        var max = Math.floor(end) //含最大值，含最小值
        var arr = []

        for (var i = 0; i < n; i++) {
          number = Math.floor(Math.random() * (max - min + 1)) + min
          if (arr.indexOf(number) !== -1) {
            //判断数组中是否有该数
            i--
          } else {
            arr.push(number)
          }
        }
        return arr
      }
      console.log(_getUniqueNums(1, 4, 4))
    </script>
  </body>
</html>
